/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     Sent.c                                                                                     *
 * \brief    AUTOSAR 4.3.1 MCAL Sent Driver                                                             *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2024/10/30     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "Sent.h"
#include "Compiler.h"
#include "OsIf.h"
#include "SchM_Sent.h"
#include "Sent_Fault.h"
#if (STD_ON == SENT_DMA_WATER_LEVEL)
#include "Dma.h"
#include "Sent_IpRegs.h"
#include "Mcal_MemLibc.h"
#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL) */
#if (STD_ON == SENT_DEV_ERROR_DETECT)
#include "Det.h"
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
#include "FuSaMcalReportError.h"
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */

/********************************************************************************************************
 *                                    Private Type Declarations                                         *
 *******************************************************************************************************/
#if (STD_ON == SENT_TIME_STAMP_FUNCTION)
/** \brief  time stamp info. */
typedef struct
{
    /** config */
    const Sent_TimeStampCfgType *cfg;
    /** time stamp channel status */
    /* PRQA S 1039 1 */
    Sent_TimeStampStaType chaSta[SENT_TIME_STAMP_NUM];
} Sent_TimeStampInfoType;
#endif /** #if (STD_ON == SENT_TIME_STAMP_FUNCTION) */

/** \brief  channel info. */
typedef struct
{
    /** config */
    const Sent_ChannelCfgType *cfg;
    /** sent channel status */
    Sent_ChannelStaType chaSta[SENT_CHANNEL_NUM];
#if (STD_ON == SENT_DMA_WATER_LEVEL)
    /** Latest location of nibble data */
    uint32 nibbleDataUpdate[SENT_CHANNEL_NUM];
    /** Latest location of serial data */
    uint32 serialDataUpdate[SENT_CHANNEL_NUM];
    /** DMA enable */
    uint32 dmaEnable;
    /** DMA channel PTR */
    Dma_ChannelConfigType *channelPtr;
#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL)  */
} Sent_ChannelInfoType;

/********************************************************************************************************
 *                                  Private Variable Definitions                                        *
 *******************************************************************************************************/
#if (STD_ON == SENT_TIME_STAMP_FUNCTION)
#if (STD_ON == SENT_CORE0_ENABLE)
#define SENT_CORE0_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and time stampe status information of core0. */
static Sent_TimeStampInfoType Sent_TimeStampHandlerCore0 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE0_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_CORE0_ENABLE) */

#if (STD_ON == SENT_CORE1_ENABLE)
#define SENT_CORE1_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and time stampe status information of core1. */
static Sent_TimeStampInfoType Sent_TimeStampHandlerCore1 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE1_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_CORE1_ENABLE) */

#if (STD_ON == SENT_CORE2_ENABLE)
#define SENT_CORE2_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and time stampe status information of core2. */
static Sent_TimeStampInfoType Sent_TimeStampHandlerCore2 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE2_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_CORE2_ENABLE) */

#if (STD_ON == SENT_CORE3_ENABLE)
#define SENT_CORE3_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and time stampe status information of core3. */
static Sent_TimeStampInfoType Sent_TimeStampHandlerCore3 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE3_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_CORE3_ENABLE) */
#endif /** #if (STD_ON == SENT_TIME_STAMP_FUNCTION) */

#if (STD_ON == SENT_CORE0_ENABLE)
#define SENT_CORE0_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and channel status information of core0. */
static Sent_ChannelInfoType Sent_ChannelHandlerCore0 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE0_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE0)
#if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN)
#define SENT_START_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore0[SENT_DMA_IRQ_WATER_LEVEL_CORE0 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_STOP_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
#else
#define SENT_CORE0_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore0[SENT_DMA_IRQ_WATER_LEVEL_CORE0 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_CORE0_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN) */
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE0) */
#endif /** #if (STD_ON == SENT_CORE0_ENABLE) */

#if (STD_ON == SENT_CORE1_ENABLE)
#define SENT_CORE1_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and channel status information of core1. */
static Sent_ChannelInfoType Sent_ChannelHandlerCore1 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE1_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE1)
#if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN)
#define SENT_START_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore1[SENT_DMA_IRQ_WATER_LEVEL_CORE1 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_STOP_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
#else
#define SENT_CORE1_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore1[SENT_DMA_IRQ_WATER_LEVEL_CORE1 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_CORE1_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN) */
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE1) */
#endif /** #if (STD_ON == SENT_CORE1_ENABLE) */

#if (STD_ON == SENT_CORE2_ENABLE)
#define SENT_CORE2_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and channel status information of core2. */
static Sent_ChannelInfoType Sent_ChannelHandlerCore2 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE2_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE2)
#if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN)
#define SENT_START_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore2[SENT_DMA_IRQ_WATER_LEVEL_CORE2 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_STOP_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
#else
#define SENT_CORE2_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore2[SENT_DMA_IRQ_WATER_LEVEL_CORE2 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_CORE2_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN) */
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE2) */
#endif /** #if (STD_ON == SENT_CORE2_ENABLE) */

#if (STD_ON == SENT_CORE3_ENABLE)
#define SENT_CORE3_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
/** Save the configuration and channel status information of core3. */
static Sent_ChannelInfoType Sent_ChannelHandlerCore3 LOCATE_ALIGNED(SENT_CACHE_LINE);
#define SENT_CORE3_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE3)
#if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN)
#define SENT_START_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore3[SENT_DMA_IRQ_WATER_LEVEL_CORE3 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_STOP_SEC_VAR_NO_INIT_NO_CACHE_UNSPECIFIED
#include "Sent_MemMap.h"
#else
#define SENT_CORE3_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
static uint32 Sent_DmaDstBuffCore3[SENT_DMA_IRQ_WATER_LEVEL_CORE3 * 3UL] LOCATE_ALIGNED(
    SENT_CACHE_LINE);
#define SENT_CORE3_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Sent_MemMap.h"
#endif /** #if (STD_ON == SENT_DMA_NO_CACHE_MAINTAIN) */
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE3) */
#endif /** #if (STD_ON == SENT_CORE3_ENABLE) */

#define SENT_START_SEC_CONST_UNSPECIFIED
#include "Sent_MemMap.h"
/********************************************************************************************************
 *                                  Private Constant Definitions                                        *
 *******************************************************************************************************/
#if (STD_ON == SENT_TIME_STAMP_FUNCTION)
/**  SENT time stamp handler */
/* PRQA S 1504,3408 1 */
Sent_TimeStampInfoType *const Sent_TimeStampHandler[4] =
{
#if (STD_ON == SENT_CORE0_ENABLE)
    &Sent_TimeStampHandlerCore0,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE0_ENABLE) */
#if (STD_ON == SENT_CORE1_ENABLE)
    &Sent_TimeStampHandlerCore1,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE1_ENABLE) */
#if (STD_ON == SENT_CORE2_ENABLE)
    &Sent_TimeStampHandlerCore2,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE2_ENABLE) */
#if (STD_ON == SENT_CORE3_ENABLE)
    &Sent_TimeStampHandlerCore3,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE3_ENABLE) */
};
#endif /** #if (STD_ON == SENT_TIME_STAMP_FUNCTION) */

/**  SENT channel handler */
/* PRQA S 1504,3408 1 */
Sent_ChannelInfoType *const Sent_ChannelHandler[4] =
{
#if (STD_ON == SENT_CORE0_ENABLE)
    &Sent_ChannelHandlerCore0,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE0_ENABLE) */
#if (STD_ON == SENT_CORE1_ENABLE)
    &Sent_ChannelHandlerCore1,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE1_ENABLE) */
#if (STD_ON == SENT_CORE2_ENABLE)
    &Sent_ChannelHandlerCore2,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE2_ENABLE) */
#if (STD_ON == SENT_CORE3_ENABLE)
    &Sent_ChannelHandlerCore3,
#else
    NULL_PTR,
#endif /** #if (STD_ON == SENT_CORE3_ENABLE) */
};

/**  SENT dma channel handler */
/* PRQA S 3408 1 */
uint32 *const Sent_DmaDstBuffHandler[4] =
{
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE0)
    Sent_DmaDstBuffCore0,
#else
    NULL_PTR,
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE0) */
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE1)
    Sent_DmaDstBuffCore1,
#else
    NULL_PTR,
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE1) */
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE2)
    Sent_DmaDstBuffCore2,
#else
    NULL_PTR,
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE2) */
#if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE3)
    Sent_DmaDstBuffCore3,
#else
    NULL_PTR,
#endif /** #if (0UL != SENT_DMA_IRQ_WATER_LEVEL_CORE3) */
};

/**  SENT dma water level */
/* PRQA S 3408 1 */
const uint32 Sent_DmaWaterLevel[4] =
{
    SENT_DMA_IRQ_WATER_LEVEL_CORE0,
    SENT_DMA_IRQ_WATER_LEVEL_CORE1,
    SENT_DMA_IRQ_WATER_LEVEL_CORE2,
    SENT_DMA_IRQ_WATER_LEVEL_CORE3,
};
#define SENT_STOP_SEC_CONST_UNSPECIFIED
#include "Sent_MemMap.h"

/********************************************************************************************************
 *                                 Imported Compiler Switch Checks                                      *
 *******************************************************************************************************/
#ifndef SENT_SW_MAJOR_VERSION
#error "SENT_SW_MAJOR_VERSION is not defined."
#endif

#ifndef SENT_SW_MINOR_VERSION
#error "SENT_SW_MINOR_VERSION is not defined."
#endif

#ifndef SENT_SW_PATCH_VERSION
#error "SENT_SW_PATCH_VERSION is not defined."
#endif

#ifndef SENT_AR_RELEASE_MAJOR_VERSION
#error "SENT_AR_RELEASE_MAJOR_VERSION is not defined."
#endif

#ifndef SENT_AR_RELEASE_MINOR_VERSION
#error "SENT_AR_RELEASE_MINOR_VERSION is not defined."
#endif

#ifndef SENT_AR_RELEASE_REVISION_VERSION
#error "SENT_AR_RELEASE_REVISION_VERSION is not defined."
#endif

#if(SENT_AR_RELEASE_MAJOR_VERSION != 4U)
#error "SENT_AR_RELEASE_MAJOR_VERSION does not match."
#endif

#if(SENT_AR_RELEASE_MINOR_VERSION != 3U)
#error "SENT_AR_RELEASE_MAJOR_VERSION does not match."
#endif

#define SENT_START_SEC_CODE
#include "Sent_MemMap.h"
/********************************************************************************************************
 *                                  Private Function Declarations                                       *
 *******************************************************************************************************/
/** *****************************************************************************************************
 * \brief Checks if the pointer is a null pointer.
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkPoint(void* point)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : point - Pointer to configuration set
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : E_OK or error ID
 *
 * Return value       : None
 *
 * Description        : Checks if the pointer is a null pointer.
 *******************************************************************************************************/
/* PRQA S 3673 1 */
static Std_ReturnType Sent_ChkPoint(void *point)
{
    Std_ReturnType errorId = E_OK;

    if (NULL_PTR == point)
    {
        errorId = SENT_E_PARAM_POINTER;
    } /* else not needed */

    return errorId;
}

/** *****************************************************************************************************
 * \brief Checks if the channel number is legal.
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkChannel(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - channel ID
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : E_OK or error ID
 *
 * Return value       : None
 *
 * Description        : Checks if the channel number is legal.
 *******************************************************************************************************/
static Std_ReturnType Sent_ChkChannel(Sent_ChannelType channelId)
{
    Std_ReturnType errorId = E_OK;

    if (channelId >= SENT_CHANNEL_NUM)
    {
        errorId = SENT_E_PARAM_CHANNEL;
    } /* else not needed */

    return errorId;
}

/** *****************************************************************************************************
 * \brief Check that the channel function is properly resourced.
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkChannelRes
 *                                      (const Sent_ChannelCfgType * ConfigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : timeStampCfg - channel config point
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : E_OK or error ID
 *
 * Return value       : None
 *
 * Description        : Check that the channel function is properly resourced.
 *******************************************************************************************************/
static Std_ReturnType Sent_ChkChannelRes(const Sent_ChannelCfgType *ConfigPtr)
{
    Std_ReturnType errorId = E_OK;
    uint8 coreId = Mcal_GetCpuIndex();

    if (coreId != ConfigPtr->coreId)
    {
        errorId = SENT_E_RES;
    } /* else not needed */

    return errorId;
}

/** *****************************************************************************************************
 * \brief Check if the channel has been initialised
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkChannelInit(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - channel ID
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : Initialised or uninitialised.
 *
 * Return value       : None
 *
 * Description        : Check if the channel has been initialised
 *******************************************************************************************************/
static Std_ReturnType Sent_ChkChannelInit(Sent_ChannelType channelId)
{
    Std_ReturnType errorId;
    uint8 coreId = Mcal_GetCpuIndex();

    if (SENT_CHANNEL_INITED == (Sent_ChannelHandler[coreId]->chaSta)[channelId])
    {
        errorId = SENT_E_ALREADY_INITIALIZED;
    }
    else
    {
        errorId = SENT_E_UNINIT;
    }

    return errorId;
}

#if (STD_ON == SENT_DMA_WATER_LEVEL)
/** *****************************************************************************************************
 * \brief sent DMA interrupt callback function.
 *
 * \verbatim
 * Syntax             : static void Sent_ChannelDmaIrqHandler(Dma_ControllerStatusType status, void *context)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None - Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : sent DMA interrupt callback function.
 *******************************************************************************************************/
static void Sent_ChannelDmaIrqHandler(Dma_ControllerStatusType status, void *context)
{
    uint8 coreId = Mcal_GetCpuIndex();
    uint32 i;
    uint32 j;
    uint32 channelNibbleValid[SENT_CHANNEL_NUM];
    Mcal_MemSet(channelNibbleValid, 0, sizeof(channelNibbleValid));
    uint32 channelSerialValid[SENT_CHANNEL_NUM];
    Mcal_MemSet(channelSerialValid, 0, sizeof(channelSerialValid));

#if (STD_OFF == SENT_DMA_NO_CACHE_MAINTAIN)
    Mcal_InvalidateCache((uint32)Sent_DmaDstBuffHandler[coreId],
                         Sent_DmaWaterLevel[coreId] * 4UL * 3UL);
#endif /** #if (STD_OFF == SENT_DMA_NO_CACHE_MAINTAIN) */

    /** #10 loop all config */
    for (i = 0UL; i < Sent_DmaWaterLevel[coreId]; i++)
    {
        for (j = 0UL; j < SENT_CHANNEL_NUM; j++)
        {
            if (GFV_CHN_FRAME1_CHN_NUM(*(Sent_DmaDstBuffHandler[coreId] + (i * 3UL))) ==
                    (Sent_ChannelHandler[coreId]->cfg)[j].channelCfg.channelId)
            {
                if (0UL == GFV_CHN_FRAME1_F(*(Sent_DmaDstBuffHandler[coreId] + (i * 3UL))))
                {
                    /* #20 nibble data */
                    Sent_Ip_NibDataProcess(*(Sent_DmaDstBuffHandler[coreId] + (i * 3UL)),
                                           *(Sent_DmaDstBuffHandler[coreId] + ((i * 3UL) + 1UL)),
                                           *(Sent_DmaDstBuffHandler[coreId] + ((i * 3UL) + 2UL)),
                                           (Sent_ChannelHandler[coreId]->cfg)[j].DmaNibbleBuff +
                                           (Sent_ChannelHandler[coreId]->nibbleDataUpdate)[j]);
                    ((Sent_ChannelHandler[coreId]->nibbleDataUpdate)[j])++;

                    if (((Sent_ChannelHandler[coreId]->nibbleDataUpdate)[j]) ==
                            (Sent_ChannelHandler[coreId]->cfg)[j].DmaNibbleBuffLen)
                    {
                        (Sent_ChannelHandler[coreId]->nibbleDataUpdate)[j] = 0UL;
                    } /* else not needed */

                    channelNibbleValid[j] = 1;
                }
                else
                {
                    /** #30 serial data */
                    Sent_Ip_SerDataProcess(*(Sent_DmaDstBuffHandler[coreId] + (i * 3UL)),
                                           *(Sent_DmaDstBuffHandler[coreId] + ((i * 3UL) + 1UL)),
                                           *(Sent_DmaDstBuffHandler[coreId] + ((i * 3UL) + 2UL)),
                                           (Sent_ChannelHandler[coreId]->cfg)[j].DmaSerBuff +
                                           (Sent_ChannelHandler[coreId]->serialDataUpdate)[j]);
                    ((Sent_ChannelHandler[coreId]->serialDataUpdate)[j])++;

                    if (((Sent_ChannelHandler[coreId]->serialDataUpdate)[j]) ==
                            (Sent_ChannelHandler[coreId]->cfg)[j].DmaSerBuffLen)
                    {
                        (Sent_ChannelHandler[coreId]->serialDataUpdate)[j] = 0UL;
                    } /* else not needed */

                    channelSerialValid[j] = 1;
                }
            } /* else not needed */
        }
    }

    for (j = 0UL; j < SENT_CHANNEL_NUM; j++)
    {
        if (1 == channelNibbleValid[j])
        {
            if (NULL_PTR != (Sent_ChannelHandler[coreId]->cfg)[j].notification)
            {
                (Sent_ChannelHandler[coreId]->cfg)[j].notification(SENT_STA_NIBBLE_READY);
            } /* else not needed */
        } /* else not needed */

        if (1 == channelSerialValid[j])
        {
            if (NULL_PTR != (Sent_ChannelHandler[coreId]->cfg)[j].notification)
            {
                (Sent_ChannelHandler[coreId]->cfg)[j].notification(SENT_STA_SER_READY);
            } /* else not needed */
        } /* else not needed */
    }
}

/** *****************************************************************************************************
 * \brief Configuring DMA
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChannelDmaDeviceToMemoryCfg(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None - Reentrant
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Configuring DMA
 *******************************************************************************************************/
static Std_ReturnType Sent_ChannelDmaDeviceToMemoryCfg(Sent_ChannelType channelId)
{
    Std_ReturnType errorId = E_OK;
    Dma_ChannelConfigType *channelPtr = NULL;
    Dma_DeviceConfigType dmaConfig;
    Dma_InstanceConfigType dmaALConfigParams;
    uint8 coreId = Mcal_GetCpuIndex();

    errorId = Dma_GetConfigParams(DMA_SENT, DMA_SENT_RX, DMA_MODULE_SENT, &dmaALConfigParams);

    if (E_OK == errorId)
    {
        channelPtr = Dma_RequestChannelWithId(dmaALConfigParams.controller, dmaALConfigParams.channelId);
        SentHook_Sent_DmaPtr();

        if (NULL_PTR == channelPtr)
        {
            errorId = SENT_E_PARAM_POINTER;
        } /* else not needed */

        if (E_OK == errorId)
        {
            /* #10.set transfer config */
            channelPtr->irqCallback = (Dma_IrqHandle)&Sent_ChannelDmaIrqHandler;
            (void)Dma_InitConfigChannel(&dmaConfig);
            dmaConfig.direction           = DMA_DEVICE_TO_MEMORY;
            dmaConfig.memsetValue         = 0U;
            dmaConfig.periodLength        = 0U;
            dmaConfig.transaction         = DMA_CYCLIC;
            dmaConfig.periodLength        = Sent_DmaWaterLevel[coreId] * 3 * 4;
            dmaConfig.processMode         = DMA_INTERRUPT;
            dmaConfig.srcAddress          = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base +
                                            DMA_FRAME1_OFF;
            dmaConfig.dstAddress          = (uint32)Sent_DmaDstBuffHandler[coreId];
            dmaConfig.srcBusWidth         = DMA_BEAT_SIZE_4_BYTE;
            dmaConfig.dstBusWidth         = DMA_BEAT_SIZE_4_BYTE;
            dmaConfig.srcMaxBurst         = DMA_BURST_LENGTH_3;
            dmaConfig.dstMaxBurst         = DMA_BURST_LENGTH_3;
            dmaConfig.srcPortSelect       = DMA_PORT_AHB32;
            dmaConfig.dstPortSelect       = DMA_PORT_AXI64;
            dmaConfig.srcIncDirection     = DMA_BURST_INCREMENTAL;
            dmaConfig.dstIncDirection     = DMA_BURST_INCREMENTAL;
            dmaConfig.bufferMode          = DMA_SINGLE_BUFFER;
            dmaConfig.loopMode            = DMA_LOOP_MODE_1;
            dmaConfig.flowControl         = DMA_DIR_DEVICE_TO_MEMORY;
            dmaConfig.transferMode        = DMA_TRANSFER_MODE_LINKLIST;
            dmaConfig.linkListTriggerMode = DMA_TRIGGER_BY_HARDWARE;
            dmaConfig.srcStrideSelect     = DMA_SFSTD;
            dmaConfig.srcStrideEnable     = TRUE;
            dmaConfig.srcStridePol        = DMA_NEGATIVE_OFFSET;
            dmaConfig.srcFineStride       = 12U;
            errorId = Dma_ConfigChannel(channelPtr, &dmaConfig);

            if (E_OK == errorId)
            {
                /** #20 EB configured waterline */
                errorId = Dma_PrepareTransmission(channelPtr, Sent_DmaWaterLevel[coreId] * 3 * 4);

                if (E_OK == errorId)
                {
                    errorId = Dma_Start(channelPtr);

                    if (E_OK == errorId)
                    {
                        (Sent_ChannelHandler[coreId]->channelPtr) = channelPtr;
                    } /* else not needed */
                }  /* else not needed */
            }  /* else not needed */
        }  /* else not needed */
    }  /* else not needed */

    return errorId;
}
#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL) */

#if (STD_ON == SENT_TIME_STAMP_FUNCTION)
/** *****************************************************************************************************
 * \brief Checks if the time stamp channel number is legal.
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkTimeSTampChn(Sent_TimeStampChannelType channelId)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - time stamp channel ID
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : E_OK or error ID
 *
 * Return value       : None
 *
 * Description        : Checks if the time stamp channel number is legal.
 *******************************************************************************************************/
static Std_ReturnType Sent_ChkTimeSTampChn(Sent_TimeStampChannelType channelId)
{
    Std_ReturnType errorId = E_OK;

    if (channelId >= SENT_TIME_STAMP_NUM)
    {
        errorId = SENT_E_PARAM_CHANNEL;
    } /* else not needed */

    return errorId;
}

/** *****************************************************************************************************
 * \brief Check if the time stamp has been initialised
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkTimeStampInit(Sent_TimeStampChannelType channelId)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - time stamp channel ID
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : Initialised or uninitialised.
 *
 * Return value       : None
 *
 * Description        : Check if the time stamp has been initialised
 *******************************************************************************************************/
static Std_ReturnType Sent_ChkTimeStampInit(Sent_TimeStampChannelType channelId)
{
    Std_ReturnType errorId;
    uint8 coreId = Mcal_GetCpuIndex();

    if (SENT_TIME_STAMP_INITED == (Sent_TimeStampHandler[coreId]->chaSta)[channelId])
    {
        errorId = SENT_E_ALREADY_INITIALIZED;
    }
    else
    {
        errorId = SENT_E_UNINIT;
    }

    return errorId;
}

/** *****************************************************************************************************
 * \brief Check that the time stamp function is properly resourced.
 *
 * \verbatim
 * Syntax             : static Std_ReturnType Sent_ChkTimeStampRes
 *                              (const Sent_TimeStampCfgType * timeStampCfg)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : timeStampCfg - time stamp config point
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : E_OK or error ID
 *
 * Return value       : None
 *
 * Description        : Check that the time stamp function is properly resourced.
 *******************************************************************************************************/
static Std_ReturnType Sent_ChkTimeStampRes(const Sent_TimeStampCfgType *timeStampCfg)
{
    Std_ReturnType errorId = E_OK;
    uint8 coreId = Mcal_GetCpuIndex();

    if (coreId != timeStampCfg->coreId)
    {
        errorId = SENT_E_RES;
    } /* else not needed */

    return errorId;
}

/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
/** *****************************************************************************************************
 * \brief The time stamp function is initialised.
 *
 * \verbatim
 * Syntax             : void Sent_TimeStampInit(Sent_TimeStampChannelType channelId,
 *                              const Sent_TimeStampCfgType * timeStampCfg)
 *
 * Service ID[hex]    : 0x00
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *                      timeStampCfg - EB configured time stamp configuration
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : The time stamp function is initialised.
 *******************************************************************************************************/
void Sent_TimeStampInit(Sent_TimeStampChannelType channelId,
                        const Sent_TimeStampCfgType *timeStampCfg)
{
    /** #10 check error */
    /* PRQA S 0311,0314 1 */
    Std_ReturnType errorId = Sent_ChkPoint((void *)timeStampCfg);
    uint8 coreId = Mcal_GetCpuIndex();

    if (E_OK == errorId)
    {
        errorId = Sent_ChkTimeSTampChn(channelId);

        if (E_OK == errorId)
        {
            errorId = Sent_ChkTimeStampInit(channelId);

            if (SENT_E_UNINIT == errorId)
            {
                errorId = Sent_ChkTimeStampRes(&timeStampCfg[channelId]);

                if (E_OK == errorId)
                {
                    /** #20 init time stamp function */
                    Sent_TimeStampHandler[coreId]->cfg = timeStampCfg;
                    Sent_Ip_TimeStampInit((Sent_TimeStampHandler[coreId]->cfg)[channelId].base,
                                          (Sent_TimeStampHandler[coreId]->cfg)[channelId].div);
                    Sent_Ip_TimeStampCntClr((Sent_TimeStampHandler[coreId]->cfg)[channelId].base);
                    (Sent_TimeStampHandler[coreId]->chaSta)[channelId] = SENT_TIME_STAMP_INITED;
                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_INIT_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_INIT_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Locking time stamp register value.
 *
 * \verbatim
 * Syntax             : void Sent_TimeStampLatch(Sent_TimeStampChannelType channelId,
 *                                      Sent_Ip_TimeStampOpType operation)
 *
 * Service ID[hex]    : 0x01
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *                      operation - latch lock register or unlatch lock register
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Locks the time stamp register value. It only locks the
 *                          registers, the real counter is still running all the time.
 *******************************************************************************************************/
void Sent_TimeStampLatch(Sent_TimeStampChannelType channelId, Sent_Ip_TimeStampOpType operation)
{
    /** #10 check error */
    Std_ReturnType errorId = Sent_ChkTimeSTampChn(channelId);
    uint8 coreId = Mcal_GetCpuIndex();

    if (E_OK == errorId)
    {
        errorId = Sent_ChkTimeStampInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkTimeStampRes(&((Sent_TimeStampHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                Sent_Ip_TimeStampLatch((Sent_TimeStampHandler[coreId]->cfg)[channelId].base, operation);
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */


#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_LATCH_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_LATCH_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Clear timestamp counter.
 *
 * \verbatim
 * Syntax             : void Sent_TimeStampCntClr(Sent_TimeStampChannelType channelId)
 *
 * Service ID[hex]    : 0x02
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Clears the timestamp counter and the register runs from 0.
 *******************************************************************************************************/
void Sent_TimeStampCntClr(Sent_TimeStampChannelType channelId)
{
    /** #10 check error */
    Std_ReturnType errorId = Sent_ChkTimeSTampChn(channelId);
    uint8 coreId = Mcal_GetCpuIndex();

    if (E_OK == errorId)
    {
        errorId = Sent_ChkTimeStampInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkTimeStampRes(&((Sent_TimeStampHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                Sent_Ip_TimeStampCntClr((Sent_TimeStampHandler[coreId]->cfg)[channelId].base);
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_CLR_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_CLR_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Gets the timestamp counter.
 *
 * \verbatim
 * Syntax             : Sent_TimeStampValueType Sent_TimeStampGet
 *                                      (Sent_TimeStampChannelType channelId)
 *
 * Service ID[hex]    : 0x03
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : time stamp val
 *
 * Return value       : None
 *
 * Description        : Gets the timestamp counter.
 *******************************************************************************************************/
Sent_TimeStampValueType Sent_TimeStampGet(Sent_TimeStampChannelType channelId)
{
    Sent_TimeStampValueType val = 0UL;
    /** #10 check error */
    Std_ReturnType errorId = Sent_ChkTimeSTampChn(channelId);
    uint8 coreId = Mcal_GetCpuIndex();

    if (E_OK == errorId)
    {
        errorId = Sent_ChkTimeStampInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkTimeStampRes(&((Sent_TimeStampHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                val = Sent_Ip_TimeStampGet((Sent_TimeStampHandler[coreId]->cfg)[channelId].base);
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_GET_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_TIME_STAMP_GET_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
    return val;
}
#endif /** #if (STD_ON == SENT_TIME_STAMP_FUNCTION) */

/** *****************************************************************************************************
 * \brief Channel function initialisation.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelInit(Sent_ChannelType channelId,
 *                                          const Sent_ChannelCfgType * ConfigPtr)
 *
 * Service ID[hex]    : 0x04
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *                      ConfigPtr - Configuration parameters for EB configuration.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Channel function initialisation.
 *******************************************************************************************************/
void Sent_ChannelInit(Sent_ChannelType channelId, const Sent_ChannelCfgType *ConfigPtr)
{
    /** #10 check error */
    /* PRQA S 0311,0314 4 */
    uint32 base;
    Sent_Ip_ChannelType ipChannelId;
    Std_ReturnType errorId = Sent_ChkPoint((void *)ConfigPtr);
    uint8 coreId = Mcal_GetCpuIndex();
    uint32 interruptVal = 0UL;

    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannel(channelId);

        if (E_OK == errorId)
        {
            errorId = Sent_ChkChannelInit(channelId);

            if (SENT_E_UNINIT == errorId)
            {
                errorId = Sent_ChkChannelRes(&(ConfigPtr[channelId]));

                if (E_OK == errorId)
                {
                    Sent_ChannelHandler[coreId]->cfg = ConfigPtr;
                    base = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base;
                    /* PRQA S 4424 1 */
                    ipChannelId = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId;
                    /** #20 init sent channel */
                    /* PRQA S 4424,4442 1 */
                    errorId = Sent_Ip_ChannelCtrl(base, ipChannelId, &(((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg));

                    if (E_OK == errorId)
                    {
                        if ((TRUE == (Sent_ChannelHandler[coreId]->cfg)[channelId].channelCfg.chnCfg.dmaNibEn) ||
                                (TRUE == (Sent_ChannelHandler[coreId]->cfg)[channelId].channelCfg.chnCfg.dmaSerEn))
                        {
#if (STD_ON == SENT_DMA_WATER_LEVEL)

                            SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_00();
                            if (0UL == (Sent_ChannelHandler[coreId]->dmaEnable))
                            {
                                errorId = Sent_ChannelDmaDeviceToMemoryCfg(channelId);
                            } /* else not needed */

                            if (E_OK == errorId)
                            {
                                (Sent_ChannelHandler[coreId]->dmaEnable)++;
                            } /* else not needed */
                            SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_00();

#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL) */
                        } /* else not needed */

                        /* PRQA S 2991,2995 1 */
                        if (E_OK == errorId)
                        {
                            /** #30 interrupt config */
                            if (0UL != ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.wdtLen)
                            {
                                interruptVal |= (uint32)SENT_ERR_IDLE;
                            } /* else not needed */

                            if (SENT_SYNC_PULSE_OPTION2 == ((
                                                                Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.calibSel)
                            {
                                interruptVal |= (uint32)SENT_ERR_THREE_RESYNC_1P5625;
                            } /* else not needed */

                            if (SENT_CAL_PULSE_25 == ((
                                                          Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.calibPulse)
                            {
                                interruptVal |= (uint32)SENT_ERR_CAL_PULSE_25;
                            }
                            else
                            {
                                interruptVal |= (uint32)SENT_ERR_CAL_LEN_20;
                            }

                            interruptVal |= (uint32)SENT_ERR_SER_OVERFLOW;
                            interruptVal |= (uint32)SENT_ERR_NIB_OVERFLOW;
                            interruptVal |= (uint32)SENT_ERR_CAL_PULSE_DRIFT_1P5625;
                            interruptVal |= (uint32)SENT_ERR_NIBBLE_VAL;
                            interruptVal |= (uint32)SENT_ERR_NUM_EDGE;
                            interruptVal |= (uint32)SENT_ERR_SER_CRC;
                            interruptVal |= (uint32)SENT_ERR_NIBBLE_CRC;
                            interruptVal |= (uint32)SENT_ERR_RIS_GLITCH;
                            interruptVal |= (uint32)SENT_ERR_FAL_GLITCH;
                            interruptVal |= (uint32)SENT_ERR_NIBBLE_PULSE;
                            interruptVal |= (uint32)SENT_ERR_CALIB_PULSE;

                            if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.frameLenChkEn)
                            {
                                interruptVal |= (uint32)SENT_ERR_FRAME_LEN;
                            } /* else not needed */

                            if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId]).serUnderRunInt)
                            {
                                interruptVal |= (uint32)SENT_ERR_SER_UNDER_RUN;
                            } /* else not needed */

                            if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId]).nibUnderRunInt)
                            {
                                interruptVal |= (uint32)SENT_ERR_NIBBLE_UNDER_RUN;
                            } /* else not needed */

                            if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.pausePulseEn)
                            {
                                interruptVal |= (uint32)SENT_ERR_PULSE_OFLOW;
                            } /* else not needed */

                            if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId]).nibReadyInt)
                            {
                                interruptVal |= (uint32)SENT_STA_NIBBLE_READY;
                            } /* else not needed */

                            if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId]).serReadyInt)
                            {
                                interruptVal |= (uint32)SENT_STA_SER_READY;
                            } /* else not needed */

                            /* PRQA S 4442 1 */
                            Sent_Ip_ChannelInterruptEnable(base, ipChannelId, interruptVal);
                            /* PRQA S 4442 1 */
                            Sent_Ip_ChannelStaClr(base, ipChannelId, 0xffffffffUL);
                            SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_00();
                            /** #40 enable DMA */
                            /* PRQA S 4442 3 */
                            Sent_Ip_ChannelDmaCtrl(base, ipChannelId,
                                                   ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.dmaNibEn,
                                                   ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.dmaSerEn);
                            /** #50 enable channel */
                            /* PRQA S 4442 1 */
                            Sent_Ip_ChannelClkEnable(base, ipChannelId, TRUE);
                            /* PRQA S 4442 1 */
                            Sent_Ip_ChannelRelease(base, ipChannelId);
                            /* PRQA S 4442 1 */
                            Sent_Ip_ChannelEnable(base, ipChannelId, TRUE);
                            SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_00();
                            (Sent_ChannelHandler[coreId]->chaSta)[channelId] = SENT_CHANNEL_INITED;
                        } /* else not needed */
                    } /* else not needed */
                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_INIT_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_INIT_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Channel deinit function.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelDeInit(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : 0x05
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Channel deinit function.
 *******************************************************************************************************/
void Sent_ChannelDeInit(Sent_ChannelType channelId)
{
    uint32 base;
    Sent_Ip_ChannelType ipChannelId;
    uint8 coreId = Mcal_GetCpuIndex();
    Std_ReturnType errorId = Sent_ChkChannel(channelId);

    /** #10 check error */
    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                base = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base;
                /* PRQA S 4442,4424 1 */
                ipChannelId = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId;
                /** #20 deinit */
                SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_01();
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelEnable(base, ipChannelId, FALSE);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelRelease(base, ipChannelId);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelClkEnable(base, ipChannelId, FALSE);
                /* PRQA S 4442 3 */
                Sent_Ip_ChannelDmaCtrl(base, ipChannelId,
                                       ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.dmaNibEn,
                                       ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.chnCfg.dmaSerEn);
                SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_01();
                Sent_Ip_ChannelStaClr(((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base,
                                      ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId, 0xffffffffUL);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelInterruptEnable(base, ipChannelId, 0UL);
                (Sent_ChannelHandler[coreId]->chaSta)[channelId] = SENT_CHANNEL_UNINIT;

                if ((TRUE == (Sent_ChannelHandler[coreId]->cfg)[channelId].channelCfg.chnCfg.dmaNibEn) ||
                        (TRUE == (Sent_ChannelHandler[coreId]->cfg)[channelId].channelCfg.chnCfg.dmaSerEn))
                {
#if (STD_ON == SENT_DMA_WATER_LEVEL)
                    SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_00();
                    (Sent_ChannelHandler[coreId]->dmaEnable)--;

                    if (0UL == (Sent_ChannelHandler[coreId]->dmaEnable))
                    {
                        Dma_Stop(Sent_ChannelHandler[coreId]->channelPtr);
                        Dma_ReleaseChannel(Sent_ChannelHandler[coreId]->channelPtr);
                        Sent_ChannelHandler[coreId]->channelPtr = NULL_PTR;
                    } /* else not needed */
                    SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_00();

#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL) */

                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_DEINIT_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_DEINIT_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Read nibble frame data.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelReadData(Sent_ChannelType channelId,
 *                                              Sent_Ip_NibDataType *nibbleData)
 *
 * Service ID[hex]    : 0x06
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : nibbleData - nibble data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Read nibble frame data.
 *******************************************************************************************************/
void Sent_ChannelReadData(Sent_ChannelType channelId, Sent_Ip_NibDataType *nibbleData)
{
    Std_ReturnType errorId = Sent_ChkChannel(channelId);
    uint8 coreId = Mcal_GetCpuIndex();

    /** #10 check error */
    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                /* PRQA S 0314 1 */
                errorId = Sent_ChkPoint((void *)nibbleData);

                if (E_OK == errorId)
                {
                    SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_04();
                    Sent_Ip_ReadNibData(((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base,
                                        ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId, nibbleData);
                    SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_04();
                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_READ_DATA_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_READ_DATA_ID, errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Read serial frame data.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelReadSerialData(Sent_ChannelType channelId,
 *                                                  Sent_Ip_SerDataType *serialData);
 *
 * Service ID[hex]    : 0x07
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : serialData - serial data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Read serial frame data.
 *******************************************************************************************************/
void Sent_ChannelReadSerialData(Sent_ChannelType channelId, Sent_Ip_SerDataType *serialData)
{
    Std_ReturnType errorId = Sent_ChkChannel(channelId);
    uint8 coreId = Mcal_GetCpuIndex();

    /** #10 check error */
    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                /* PRQA S 0314 1 */
                errorId = Sent_ChkPoint((void *)serialData);

                if (E_OK == errorId)
                {
                    SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_03();
                    Sent_Ip_ReadSerData(((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base,
                                        ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId, serialData);
                    SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_03();
                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_READ_SERIAL_DATA_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_READ_SERIAL_DATA_ID,
                                   errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Gets the bit position corresponding to the 1 of the lowest bit.
 *
 * \verbatim
 * Syntax             : static uint32 Sent_GetLowestInterruptBitPos(uint32 reg)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : reg - register val
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : position
 *
 * Return value       : None
 *
 * Description        : Gets the bit position corresponding to the 1 of the lowest bit.
 * \endverbatim
 *******************************************************************************************************/
static uint32 Sent_GetLowestInterruptBitPos(uint32 reg)
{
    uint32 pos = 0;
    uint32 regVal = reg;

    /* #10 get low interrupt bit pos */
    while ((regVal & 0x01UL) == 0x0UL)
    {
        regVal >>= 1UL;
        ++pos;
    }

    return pos;
}

/** *****************************************************************************************************
 * \brief IRQ handler.Callback function for handling all interrupts into the corresponding channel.
 *
 * \verbatim
 * Syntax             : void Sent_IrqHandler(uint32 base)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non-Reentrant
 *
 * Parameters (in)    : base - sent base address
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : IRQ handler.Callback function for handling all interrupts
 *                          into the corresponding channel.
 * \endverbatim
 *******************************************************************************************************/
void Sent_IrqHandler(uint32 base)
{
    uint32 i = 0UL;
    uint8 coreId = Mcal_GetCpuIndex();
    /** #10 See which channel triggered the interrupt. */
    uint32 getChanIrqSta = Sent_Ip_GetChannelIntSta(base);
    Sent_Ip_ChannelType channelId;
    Sent_Ip_ChannelStaType channelErrSta;
    uint32 interruptSta;

    if (0UL != getChanIrqSta)
    {
        /* PRQA S 4342 1 */
        channelId = (Sent_Ip_ChannelType)Sent_GetLowestInterruptBitPos(getChanIrqSta);

        if (SENT_CHANNEL_MAX > channelId)
        {
            /** #20 See what type of interrupt it is. */
            interruptSta = Sent_Ip_ChannelIrqStaGet(base, channelId);

            if (0UL != interruptSta)
            {
                /* PRQA S 4342,4394 1 */
                channelErrSta = (Sent_Ip_ChannelStaType)(0x01UL << Sent_GetLowestInterruptBitPos(interruptSta));

                /** #30 Find the corresponding interrupt handler function. */
                while (!((base == (Sent_ChannelHandler[coreId]->cfg)[i].channelCfg.base) &&
                         (channelId == (Sent_ChannelHandler[coreId]->cfg)[i].channelCfg.channelId)))
                {
                    ++i;
                }

                if ((E_OK == Sent_ChkChannel(i)) &&
                        (NULL_PTR != (Sent_ChannelHandler[coreId]->cfg)[i].notification))
                {
                    (Sent_ChannelHandler[coreId]->cfg)[i].notification(channelErrSta);
                } /* else not needed */

                /** #40 clear all interrupt status */
                Sent_Ip_ChannelStaClr(base, channelId, interruptSta);
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */
} /* else not needed */

#if (STD_ON == SENT_VERSION_INFO_API)
/** *****************************************************************************************************
 * \brief This service returns the version information of this module.
 *
 * \verbatim
 * Syntax             : void Sent_GetVersionInfo(Std_VersionInfoType*
 *                                                          VersionInfoPtr)
 *
 * Service ID[hex]    : 0x08
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : VersionInfoPtr - Pointer to where to store the version
 *                        information of this module
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Returns the version information of this module
 * \endverbatim
 *******************************************************************************************************/
void Sent_GetVersionInfo(Std_VersionInfoType *VerInfoPtr)
{
    if (NULL_PTR == VerInfoPtr)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_GET_VERSION_INFO_ID,
                              SENT_E_PARAM_POINTER);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_GET_VERSION_INFO_ID,
                                   SENT_E_PARAM_POINTER);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    }
    else
    {
        VerInfoPtr->vendorID = SENT_VENDOR_ID;
        VerInfoPtr->moduleID = SENT_MODULE_ID;
        VerInfoPtr->sw_major_version = SENT_SW_MAJOR_VERSION;
        VerInfoPtr->sw_minor_version = SENT_SW_MINOR_VERSION;
        VerInfoPtr->sw_patch_version = SENT_SW_PATCH_VERSION;
    }
}
#endif /** #if (STD_ON == SENT_VERSION_INFO_API) */

/** *****************************************************************************************************
 * \brief Actual Calculation Result of Tick Period
 *
 * \verbatim
 * Syntax             : Sent_ChannelActualTickType Sent_ChannelActualTick(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : 0x09
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Actual Calculation Result of Tick Period
 * \endverbatim
 *******************************************************************************************************/
Sent_ChannelActualTickType Sent_ChannelActualTick(Sent_ChannelType channelId)
{
    Std_ReturnType errorId = Sent_ChkChannel(channelId);
    uint8 coreId = Mcal_GetCpuIndex();
    Sent_ChannelActualTickType val = 0UL;

    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                val = Sent_Ip_GetChannelActualTick(((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base,
                                                   ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId);
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_ACTUAL_TICK_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_ACTUAL_TICK_ID,
                                   errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
    return val;
}

/** *****************************************************************************************************
 * \brief Actual Calculation Result of Tick Period
 *
 * \verbatim
 * Syntax             : void Sent_ChannelUpdateTick(Sent_ChannelType channelId, uint32 div,
 *                              uint32 tick, boolean clrFifo)
 *
 * Service ID[hex]    : 0x0a
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *                      preDiv - crossover factor
 *                      tick - tick counter
 *                      clrFifo - Whether or not the fifo needs to be cleared
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Actual Calculation Result of Tick Period
 *                      SentTick(us) = (1 / (RootClk(Mhz) / preDiv)) * tick
 * \endverbatim
 *******************************************************************************************************/
void Sent_ChannelUpdateTick(Sent_ChannelType channelId, uint32 preDiv, uint32 tick, boolean clrFifo)
{
    uint32 base;
    Sent_Ip_ChannelType ipChannelId;
    Std_ReturnType errorId = Sent_ChkChannel(channelId);
    uint8 coreId = Mcal_GetCpuIndex();

    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                /** #10 update div and tick */
                base = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.base;
                /* PRQA S 4442,4424 1 */
                ipChannelId = ((Sent_ChannelHandler[coreId]->cfg)[channelId]).channelCfg.channelId;

                SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_02();
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelDivCtrl(base, ipChannelId, tick, preDiv);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelEnable(base, ipChannelId, FALSE);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelClkEnable(base, ipChannelId, FALSE);
                /** delay (1/rootclk) * div ) * 3 */
                /* PRQA S 3200,1800,4454 1 */
                Mcal_udelay(((preDiv / 100) * 3) + 1);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelClkEnable(base, ipChannelId, TRUE);
                /* PRQA S 4442 1 */
                Sent_Ip_ChannelEnable(base, ipChannelId, TRUE);

                if (TRUE == clrFifo)
                {
                    /* PRQA S 4442 1 */
                    Sent_Ip_ChannelRelease(base, ipChannelId);
                } /* else not needed */

                SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_02();
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_ACTUAL_TICK_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_ACTUAL_TICK_ID,
                                   errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

#if (STD_ON == SENT_DMA_WATER_LEVEL)
/** *****************************************************************************************************
 * \brief Get DMA data interface.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelDmaReadData(Sent_ChannelType channelId,
 *                                              Sent_Ip_NibDataType *nibbleData)
 *
 * Service ID[hex]    : 0x0b
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None - Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : nibbleData - nibble data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Get DMA data interface.
 *******************************************************************************************************/
void Sent_ChannelDmaReadData(Sent_ChannelType channelId, Sent_Ip_NibDataType *nibbleData)
{
    Std_ReturnType errorId = Sent_ChkChannel(channelId);
    uint8 coreId = Mcal_GetCpuIndex();
    uint32 i;
    uint32 newNibbleCounter;
    Sent_Ip_NibDataType *nibbDataBak = nibbleData;
    uint32 j = 0UL;

    /** #10 check error */
    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                /* PRQA S 0314 1 */
                errorId = Sent_ChkPoint((void *)nibbleData);

                if (E_OK == errorId)
                {
                    SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_03();
                    if (0UL == (Sent_ChannelHandler[coreId]->nibbleDataUpdate)[channelId])
                    {
                        newNibbleCounter = (Sent_ChannelHandler[coreId]->cfg)[channelId].DmaNibbleBuffLen - 1UL;
                    }
                    else
                    {
                        newNibbleCounter = (Sent_ChannelHandler[coreId]->nibbleDataUpdate)[channelId] - 1UL;
                    }

                    for (i = 0UL; i < (Sent_ChannelHandler[coreId]->cfg)[channelId].DmaNibbleBuffLen; i++)
                    {
                        if (TRUE == ((
                                            Sent_ChannelHandler[coreId]->cfg)[channelId].DmaNibbleBuff)[newNibbleCounter].validData)
                        {
                            Mcal_MemCpy(&nibbDataBak[j], &((
                                                            Sent_ChannelHandler[coreId]->cfg)[channelId].DmaNibbleBuff)[newNibbleCounter],
                                        sizeof(Sent_Ip_NibDataType));
                            ((Sent_ChannelHandler[coreId]->cfg)[channelId].DmaNibbleBuff)[newNibbleCounter].validData = FALSE;
                            ++j;
                        }
                        else
                        {
                            break;
                        }

                        newNibbleCounter--;

                        if (0xffffffffUL == newNibbleCounter)
                        {
                            newNibbleCounter = (Sent_ChannelHandler[coreId]->cfg)[channelId].DmaNibbleBuffLen - 1UL;
                        } /* else not needed */
                    }
                    SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_03();
                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_DMA_READ_DATA_ID, errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_DMA_READ_DATA_ID,
                                   errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}

/** *****************************************************************************************************
 * \brief Get DMA data interface.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelDmaReadSerialData(Sent_ChannelType channelId,
 *                                                              Sent_Ip_SerDataType *SerialData)
 *
 * Service ID[hex]    : 0x0c
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None - Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : SerialData - serial data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Get DMA data interface.
 *******************************************************************************************************/
void Sent_ChannelDmaReadSerialData(Sent_ChannelType channelId, Sent_Ip_SerDataType *SerialData)
{
    Std_ReturnType errorId = Sent_ChkChannel(channelId);
    uint8 coreId = Mcal_GetCpuIndex();
    uint32 i;
    uint32 newSerialCounter;
    Sent_Ip_SerDataType *serDataBak = SerialData;
    uint32 j = 0UL;

    /** #10 check error */
    if (E_OK == errorId)
    {
        errorId = Sent_ChkChannelInit(channelId);

        if (SENT_E_ALREADY_INITIALIZED == errorId)
        {
            errorId = Sent_ChkChannelRes(&((Sent_ChannelHandler[coreId]->cfg)[channelId]));

            if (E_OK == errorId)
            {
                /* PRQA S 0314 1 */
                errorId = Sent_ChkPoint((void *)SerialData);

                if (E_OK == errorId)
                {
                    SchM_Enter_Sent_SENT_EXCLUSIVE_AREA_04();
                    if (0UL == (Sent_ChannelHandler[coreId]->serialDataUpdate)[channelId])
                    {
                        newSerialCounter = (Sent_ChannelHandler[coreId]->cfg)[channelId].DmaSerBuffLen - 1UL;
                    }
                    else
                    {
                        newSerialCounter = (Sent_ChannelHandler[coreId]->serialDataUpdate)[channelId] - 1UL;
                    }

                    for (i = 0UL; i < (Sent_ChannelHandler[coreId]->cfg)[channelId].DmaSerBuffLen; i++)
                    {
                        if (TRUE == ((Sent_ChannelHandler[coreId]->cfg)[channelId].DmaSerBuff)[newSerialCounter].validData)
                        {
                            Mcal_MemCpy(&serDataBak[j], &((
                                                            Sent_ChannelHandler[coreId]->cfg)[channelId].DmaSerBuff)[newSerialCounter],
                                        sizeof(Sent_Ip_SerDataType));
                            ((Sent_ChannelHandler[coreId]->cfg)[channelId].DmaSerBuff)[newSerialCounter].validData = FALSE;
                            ++j;
                        }
                        else
                        {
                            break;
                        }

                        newSerialCounter--;

                        if (0xffffffffUL == newSerialCounter)
                        {
                            newSerialCounter = (Sent_ChannelHandler[coreId]->cfg)[channelId].DmaSerBuffLen - 1UL;
                        }
                    }
                    SchM_Exit_Sent_SENT_EXCLUSIVE_AREA_04();
                } /* else not needed */
            } /* else not needed */
        } /* else not needed */
    } /* else not needed */

#if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT))

    if (E_OK != errorId)
    {
#if (STD_ON == SENT_DEV_ERROR_DETECT)
        (void)Det_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_DMA_READ_SERIAL_DATA_ID,
                              errorId);
#endif /** #if (STD_ON == SENT_DEV_ERROR_DETECT) */
#if (STD_ON == SENT_SAFETY_ENABLE)
        (void)FuSaMcal_ReportError(SENT_MODULE_ID, SENT_INSTANCE_ID, SENT_CHANNEL_DMA_READ_SERIAL_DATA_ID,
                                   errorId);
#endif /** #if (STD_ON == SENT_SAFETY_ENABLE) */
    } /* else not needed */

#endif /** #if ((STD_ON == SENT_SAFETY_ENABLE) || (STD_ON == SENT_DEV_ERROR_DETECT)) */
}
#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL) */

#define SENT_STOP_SEC_CODE
#include "Sent_MemMap.h"
/* End of file */
